public class Longest2 {
    //解法二
    public int longestC(String s1,String s2){
        int n=s1.length();
        int m=s2.length();
        //先求大小再在后面加，就不会影响mn的值

        s1=" "+s1;s2=" "+s2;//以此改变dp表，下标不用强制对齐
        int[][]dp=new int[n+1][n+1];

        for (int i=1;i<n;i++){
            for (int j=1;j<m;j++){
                if (s1.charAt(i)==s2.charAt(j)){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else {
                    dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }

        }
        return dp[m][n];
    }
}
